<?php
/**
 * 模块启动文件
 */
namespace addons\vote;
use system\Addon;

class Vote extends Addon {
	public function getName()
	{
		return 'vote';
	}

	public function getVersion()
	{
		return '1.0.0';
	}

	public function getAuthor()
	{
		return 'Colin';
	}

	public function getDesc()
	{
		return '投票组件';
	}

	public function install()
	{
		$sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@vote_log`(
id int unsigned not null auto_increment primary key , 
uid int unsigned not null default 0 comment '用户ID' , 
touid int unsigned null default 0 comment '被投票人ID' , 
`comment` varchar(200) null comment '评价' , 
create_time int(10) default 0 comment '添加时间',
key uid(`uid`),
key touid(`touid`)
)engine=myisam charset=utf8 comment='投票记录';";
		$sql['1.0.0'][] = "alter table @member add column (
ticket int default 0 comment '获取票数' , 
ticket_put int default 0 comment '已投票数' , 
`number` varchar(10) comment '用户编号' , 
deparent_id tinyint(2) default 0 comment '部门ID',
`name` varchar(30) comment '用户名称',
`user_avatar` varchar(255) comment '用户头像'
);
alter table @member add unique index number(`number`);";
		return $sql;
	}

	public function uninstall()
	{
		$sql['1.0.0'][] = "DROP TABLE `@vote_log`;
drop index `number` on @member;
alter table @member drop ticket;
alter table @member drop ticket_put;
alter table @member drop number;
alter table @member drop name;
alter table @member drop user_avatar;";
		return $sql;
	}

	public function onInitMenu(&$data = []){
		return [
			[
				'name'  => 'vote',
				'title' => '投票管理',
				'icon'  => 'layui-icon-set',
				'list'  => [
					['name' => 'voteList', 'title' => '投票记录', 'auth_name' => 'Vote', 'action' => 'index' , 'jump' => '---vote/index'],
				]
			],
		];
	}

	/**
	 * 依赖扩展
	 * @return array|string[]
	 * @author Colin <amcolin@126.com>
	 * @date 2022-02-08 下午9:52
	 */
	public function dependents() {
		return [
			'member'
		];
	}
}